package com.ejd.web.bo.impl;

import java.io.Serializable;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.ejd.utils.DESPlusUtil;
import com.ejd.web.bo.AbstractGoods;
import com.ejd.web.bo.Product;

public class Goods extends AbstractGoods implements Serializable {
	
	private static final long serialVersionUID = -8106629465344224739L;
	private Productunit unit;
	private Stakeholder provider;
	private Set<GoodsProperties> properties;
	
	public Goods(){
		
	}
	
	public Productunit getUnit() {
		return unit;
	}

	public void setUnit(Productunit unit) {
		this.unit = unit;
	}

	public Stakeholder getProvider() {
		return provider;
	}

	public void setProvider(Stakeholder provider) {
		this.provider = provider;
	}

	public Set<GoodsProperties> getProperties() {
		return properties;
	}

	public void setProperties(Set<GoodsProperties> properties) {
		this.properties = properties;
	}
	
	public String getShowImage() {//用于没有多个属性的值 image直接存储在主数据中
		String result = "";
		if (null != this.getImage1() && !("".equals(this.getImage1()))) {
			result = this.getImage1();
		}
		if (null != this.getProperties() || !(this.getProperties().isEmpty())) {
			result = this.getProperties().iterator().next().getSfield1();
		}
		return result;
	}
	public List<String> getImages() {
		List<String> result = new ArrayList<String>();
		if (null != this.getImage1() && !("".equals(this.getImage1()))) {
			result.add(this.getImage1());
		}
		if (null != this.getImage2() && !("".equals(this.getImage2()))) {
			result.add(this.getImage2());
		}
		if (null != this.getImage3() && !("".equals(this.getImage3()))) {
			result.add(this.getImage3());
		}
		if (null != this.getImage4() && !("".equals(this.getImage4()))) {
			result.add(this.getImage4());
		}
		if (null != this.getImage5() && !("".equals(this.getImage5()))) {
			result.add(this.getImage5());
		}
		if (null != this.getImage6() && !("".equals(this.getImage6()))) {
			result.add(this.getImage6());
		}
		if (null != this.getImage7() && !("".equals(this.getImage7()))) {
			result.add(this.getImage7());
		}
		if (null != this.getImage8() && !("".equals(this.getImage8()))) {
			result.add(this.getImage8());
		}
		if (null != this.getImage9() && !("".equals(this.getImage9()))) {
			result.add(this.getImage9());
		}
		if (null != this.getImage10() && !("".equals(this.getImage10()))) {
			result.add(this.getImage10());
		}
		
		return result;
	}
	public Map<String,String> getPropertiesMapShowImages() {//用于有多个属性的值 image直接存储在附加属性中,显示第1幅图片的
		Map result = new HashMap<String,String>();
		if (null != getProperties() || !(getProperties().isEmpty())) {
			for (GoodsProperties property:getProperties()) {
				String mapKey = this.getCode()+property.getColor();
				result.put(mapKey, property.getSfield1());
			}
		}
		return result;
	}
	
	public Map<String,List<String>> getPropertiesMapImages() {//用于有多个属性的值 image直接存储在附加属性中,显示第1幅图片的
		Map result = new HashMap<String,List<String>>();
		if (null != getProperties() || !(getProperties().isEmpty())) {
			for (GoodsProperties property:getProperties()) {
				List<String> imageList = new ArrayList<String>();
				imageList.add(property.getSfield1());
				imageList.add(property.getSfield2());
				imageList.add(property.getSfield3());
				imageList.add(property.getSfield4());
				imageList.add(property.getSfield5());
				imageList.add(property.getSfield6());
				imageList.add(property.getSfield7());
				imageList.add(property.getSfield8());
				imageList.add(property.getSfield9());
				imageList.add(property.getSfield10());
				String mapKey = this.getCode()+property.getColor();
				result.put(mapKey, imageList);
			}
		}
		return result;
	}
	
	public String getDesId() {
		return DESPlusUtil.encrypt(this.getId().toString());
	}
	public String getDesCode() {
			return DESPlusUtil.encrypt(this.getCode());
	}
	public String getDesPrimaryCategoryCode(){
		return DESPlusUtil.encrypt(this.getPrimaryCategoryCode());
	}
	
}
